package atlantik.ui;

import java.awt.GridLayout;

import javax.swing.JPanel;

import modelz.ui.PeerMap;
import modelz.ui.PeerMapListener;

import atlantik.game.Atlantik;
import atlantik.game.AtlantikState;
import atlantik.game.Game;
import atlantik.game.Player;
import atlantik.game.Game.Option;
import atlantik.peer.GameOptionPeer;

public class GameConfigurationState implements GUIState,
		PeerMapListener<GameOptionPeer> {

	private final JPanel configPanel = new JPanel();

	private final Game game;

	private final PeerMap<Option, GameOptionPeer> peerMap;

	public GameConfigurationState(Atlantik client) {
		AtlantikState state = client.getState();
		Player self = state.self();
		game = self.getGame();
		peerMap = new PeerMap<Game.Option, GameOptionPeer>(client, game
				.options(), GameOptionPeer.class);
		peerMap.addListener(this);
		
		configPanel.setLayout(new GridLayout(0, 1));
	}

	public void begin(GUI gui) {
		gui.add(configPanel);
	}

	public void end(GUI gui) {
		gui.remove(configPanel);
	}

	public void itemAdded(GameOptionPeer item) {
		configPanel.add(item.getComponent());
	}

	public void itemRemoved(GameOptionPeer item) {
		configPanel.remove(item.getComponent());
	}

}
